﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using XbdSoft.WPFVersion.Common;

namespace XbdSoft.WPFVersion.ViewModel
{
    public class SelectedDownloadStatusConverter:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                var status = (DownloadStatus)value; 
                return Util.DownloadStatusValueMapping.Keys.ToList().FindIndex(c => c == status);
            }
            catch { }
            return 0;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                var index =(int)value;
                if (index >= 0)
                    return Util.DownloadStatusValueMapping.Keys.ElementAt(index);
            }
            catch { }
            return DownloadStatus.All;
        }
    }
}
